package com.tmz.web;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.transaction.JOnASTransactionManagerLookup;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.tmz.dao.JornadasDAO;
import com.tmz.dao.JornadasDAOImpl;
import com.tmz.dao.UserDAO;
import com.tmz.dao.UserDAOImpl;
import com.tmz.domain.Apuesta;
import com.tmz.domain.Jornada;
import com.tmz.domain.Partido;
import com.tmz.domain.User;
import com.tmz.utils.QuinielaUtil;
import com.tmz.utils.UsuarioHabilitado;

public class JornadasAction extends ActionSupport implements ModelDriven<Jornada>, UsuarioHabilitado{

	private static final long serialVersionUID = -6659925652584240539L;

	private User user = new User();
	private Jornada jornada = new Jornada();
	private List<Jornada> jornadasList = new ArrayList<Jornada>();
	private JornadasDAO jornadasDAO = new JornadasDAOImpl();
	
	//private Apuesta apuesta = new Apuesta();
	
	/*public void setapuesta(Apuesta apuesta){
		this.apuesta = apuesta;
	}*/
	

	public Jornada getModel() {
		return jornada;
	}
	 
	public String listTodas()
	{
		jornadasList = jornadasDAO.listJornadas();
		if(jornadasList != null){
			System.out.println(jornadasList.size());
		}
		return SUCCESS;
	}
	public String listActivas()
	{
		jornadasList = jornadasDAO.listJornadasActivas();
		return SUCCESS;
	}
	public String listHistorico()
	{
		jornadasList = jornadasDAO.listJornadas();
		return SUCCESS;
	}
		
	public Jornada getJornada() {
		return jornada;
	}

	public List<Jornada> getJornadasList() {
		return jornadasList;
	}

	public void setJornadasList(List<Jornada> jornadasList) {
		this.jornadasList = jornadasList;
	}

	public void setJornada(Jornada jornada) {
		this.jornada = jornada;
	}

	public void setUsuario(User usuario) {
		this.user = usuario;
		
	}
	
	public String addJornada(){
		Jornada j = QuinielaUtil.getNextJornada();	
		if(j!=null)
			jornadasDAO.saveJornada(j);
		/*j = QuinielaUtil.getLastJornada();
		jornadasDAO.saveJornada(j);*/
		return SUCCESS;
	}

	public String nextJornada()	{
		jornadasList = jornadasDAO.listJornadasActivas();
		if(jornadasList != null){
			if(jornadasList.size() == 1){
				this.jornada = jornadasList.get(0);
			}
		}
		return SUCCESS;
	}
	
	public String lastJornada()	{
		jornadasList = jornadasDAO.listJornadasHistorico();
		if(jornadasList != null){
			System.out.println(jornadasList.size());
		}
		return SUCCESS;
	}
	
	public String getApuestaByJornada(){
		jornadasList = jornadasDAO.listJornadasActivas();
		if(jornadasList != null){
			if(jornadasList.size() == 1){
				this.jornada = jornadasList.get(0);
			}
		}
		return SUCCESS;
	}

}
